package cc.idoone.spring_boot_hello.mybatis.h2;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hemj
 * @since 2017/10/19
 */
@Configuration
// 注意，由于MapperScannerConfigurer执行的比较早，所以必须有下面的注解
@AutoConfigureAfter(name = "sqlSessionFactory")
public class MyBatisMapperScannerConfig {

	// 或者使用 @MapperScan
	@Bean
	public MapperScannerConfigurer mapperScannerConfigurer() {
		MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
		mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
		mapperScannerConfigurer.setBasePackage("cc.idoone.spring_boot_hello.mybatis.h2.dao");
		return mapperScannerConfigurer;
	}

}
